package org.keyyond.ms.commonservice.util;

import org.keyyond.ms.commonservice.service.MsCommonMessageLogService;
import org.keyyond.ms.core.model.MsCommonMessageLogVo;
import org.keyyond.ms.core.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CommonBeanUtils {

	@Autowired
	MsCommonMessageLogService messageLogService;

	/**
	 * 方法功能描述 记录日志 
	 * @author YCR 
	 * @param 
	 * @return void 
	 * @throws
	 */
	public void addMessageLog(MsCommonMessageLogVo messageLog) {
		messageLog.setCreateby(org.keyyond.ms.core.util.Constant.CONST_SYSTEM_LOG_CREATEON);
		messageLog.setModifyby(org.keyyond.ms.core.util.Constant.CONST_SYSTEM_LOG_MODIFYON);
		String log = JsonUtil.toJson(messageLog);
		String result = messageLogService.addMessageLog(log);
		if (result.contains(org.keyyond.ms.core.util.Constant.CONST_CHECK_RESULT_EXCEPTION)
				|| result.contains(org.keyyond.ms.core.util.Constant.CONST_CHECK_RESULT_FAIL)) {
			MsCommonMessageLogVo newlog = new MsCommonMessageLogVo();
			newlog.setContent(messageLog.getContent());
			newlog.setLogtype(org.keyyond.ms.core.util.Constant.CONST_MESSAGE_LOG_EXCEPTION);
			newlog.setReturnmessage(result);
			newlog.setCreateby(org.keyyond.ms.core.util.Constant.CONST_SYSTEM_LOG_CREATEON);
			newlog.setModifyby(org.keyyond.ms.core.util.Constant.CONST_SYSTEM_LOG_MODIFYON);
			String resultLog = JsonUtil.toJson(newlog);
			messageLogService.addMessageLog(resultLog);
		}
	}

}
